package com.atguigu4.search_sort.exer1;

/**
 * ClassName: arrary_test2
 * Description:
 *数组的缩容：
 * 现有数组 int[] arr={1,2,3,4,5,6,7}。现需删除数组中索引为4的元素
 * @Author liu
 * @Create 2024/8/12 19:35
 * @Version 1.0
 */

public class arrary_test2 {
    public static void main(String[] args) {
        //不建数组

//        int[] arr={1,2,3,4,5,6,7};
//        int indent = 4;
//        for (int i = indent; i <arr.length-1 ; i++) {
//            arr[i] =arr[i +1];
//        }
//        arr[arr.length-1]=0;
//        for (int i = 0; i <arr.length ; i++) {
//            System.out.print(arr[i]+" ");
//
//        }

        //建数组
        int[] arr={1,2,3,4,5,6,7};
        int index = 4;
        int[] newArr = new int[arr.length - 1];
        for (int i = 0; i < index; i++) {
            newArr[i] = arr[i];
        }

        for(int i = index;i < arr.length - 1;i++){
            newArr[i] = arr[i + 1];
        }

        arr = newArr;
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");

        }


    }

}
